import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
 * retryUI is the last GUI that will show the game result and make choices of the player that will they want to continues or not
 * @author Kridpak Vorametpasuk 55105466348
 * @version May 09 2013
 */
public class RetryUI extends JFrame {

	private JLabel message,playerName;
	private JButton retry, menu;
	private JPanel panelCen,panelBot,panelMid;
	private int score;

	/**
	 * get the score and save the player score
	 * @param score is the total score the player got from the game
	 */
	public RetryUI(int score) {
		this.score = score;
	}

	/**
	 * create last panel and show the result 
	 */
	public void initComponent() {
		panelCen = new JPanel();
		message = new JLabel("Game OVER!!!");
		message.setFont(new Font("San Serif", Font.BOLD, 78));
		message.setForeground(Color.RED);
		panelCen.add(message);
		
		add(panelCen, BorderLayout.NORTH);
		
		panelMid = new JPanel();
		playerName = new JLabel(FirstUI.name+"!!! You got "+score+ "points");
		playerName.setFont(new Font("San Serif", Font.ROMAN_BASELINE, 36));
		panelMid.add(playerName);
		
		add(panelMid, BorderLayout.CENTER);
		
		panelBot = new JPanel();
		retry = new JButton("RETRY");
		menu = new JButton("Back to MENU");
		panelBot.add(retry);
		panelBot.add(menu);
		retry.addActionListener(new retryListener());
		menu.addActionListener(new menuListener());
		
		add(panelBot,BorderLayout.SOUTH);
	}


	/**
	 * run is the method that will call the program to create the fame and set up the frame.
	 */
	public void run(){
		RetryUI first = new RetryUI(score);
		first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		first.setTitle("Think it Up!!");
		first.setSize(730, 250);
		first.initComponent();
		first.setVisible(true);
	}
	
	/**
	 * command for the retry button if the player want ot play the game again
	 *
	 */
	class retryListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			GameFactory factory = GameFactory.getInstance();
			GameUI game = new GameUI(factory);
			game.run();
			dispose();
		}
		
	}

	/**
	 * 
	 *command for the player want to change game level or their name
	 */
	class menuListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			FirstUI first = new FirstUI();
			first.run();
			dispose();
		}
		
	}
}
